package com.godox.beauty.vm

import androidx.lifecycle.MutableLiveData
import com.godox.beauty.data.MineBean
import com.godox.beauty.network.apiService
import com.godox.common.base.viewmodel.BaseViewModel
import com.godox.common.callback.livedata.BooleanLiveData
import com.godox.common.ext.request
import com.godox.common.ext.requestNoCheck
import com.godox.common.network.AppException
import com.godox.common.network.BaseResponse
import com.godox.common.state.ResultState

class MainViewModel : BaseViewModel() {
    val demoLiveData = BooleanLiveData()

    val errorLiveData = MutableLiveData<AppException>()

    val mineLiveData = MutableLiveData<MineBean>()

    val mine3LiveData = MutableLiveData<ResultState<BaseResponse<MineBean>>>()

    val mine2LiveData = MutableLiveData<ResultState<MineBean>>()

    val mineListLiveData = MutableLiveData<MutableList<MineBean>>()

    val mineList2LiveData = MutableLiveData<ResultState<MutableList<MineBean>>>()


    fun getMine() {
        request({ apiService.getMine() }, success = {
            mineLiveData.value = it
        }, error = {
            //TODO 可自定义错误
            errorLiveData.value = it
        })
    }

    fun getMine2() {
        request({ apiService.getMine() }, mine2LiveData)
    }

    fun getMine3() {
        requestNoCheck({ apiService.getMine() }, success = {
            mineLiveData.value = it.data
        }, error = {
            //TODO 可自定义错误
            errorLiveData.value = it
        })
    }

    fun getMine4() {
        requestNoCheck({ apiService.getMine() }, mine3LiveData)
    }




    fun getMineList() {
        request({ apiService.getMineList() }, success = {
            mineListLiveData.value = it
        }, error = {
            //TODO 可自定义错误
            errorLiveData.value = it
        })
    }

    fun getMineList2() {
        request({ apiService.getMineList() }, mineList2LiveData)
    }


}